﻿Imports System.Data.OleDb

Public Class MyVolkswagen
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If System.Web.HttpContext.Current.User.Identity.IsAuthenticated Then
        Else
            Response.Redirect("Account/Login.aspx")
        End If
        Dim sql As String = "SELECT * FROM UserProfile WHERE Username= @f1"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        conn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@f1", User.Identity.Name)
        'Creating a data reader to read data
        Dim datareader = cmd.ExecuteReader()
        If datareader.HasRows Then
            datareader.Read()
            'If Not IsDBNull(datareader("Title")) Then txtTitle.SelectedValue = datareader("Title")
            'If Not IsDBNull(datareader("FirstName")) Then txtFirstName.Text = datareader("FirstName")
            'If Not IsDBNull(datareader("LastName")) Then txtLastName.Text = datareader("LastName")
            'If Not IsDBNull(datareader("DOB")) Then txtDOB.Text = datareader("DOB")
            'If Not IsDBNull(datareader("Address1")) Then txtAddress1.Text = datareader("Address1")
            'If Not IsDBNull(datareader("Address2")) Then txtAddress2.Text = datareader("Address2")
            'If Not IsDBNull(datareader("Town")) Then txtTown.Text = datareader("Town")
            'If Not IsDBNull(datareader("City")) Then txtCity.Text = datareader("City")
            'If Not IsDBNull(datareader("Postcode")) Then txtPostCode.Text = datareader("Postcode")
            'If Not IsDBNull(datareader("TelNo")) Then txtTelNo.Text = datareader("TelNo")
            'If Not IsDBNull(datareader("Gender")) Then txtGender.SelectedValue = datareader("Gender")
            'If Not IsDBNull(datareader("AboutMe")) Then txtAboutMe.Text = datareader("AboutMe")
            'If Not IsDBNull(datareader("PreferredFuel")) Then txtPreferredFuel.SelectedValue = datareader("PreferredFuel")
            'If Not IsDBNull(datareader("FavouriteColour")) Then txtFavouriteColour.Text = datareader("FavouriteColour")
            If Not IsDBNull(datareader("UserImage")) Then userImage.ImageUrl = datareader("UserImage")
        Else
            userImage.ImageUrl = "/Images/User.png"
        End If
        datareader.Close()
        cmd.Dispose()
        conn.Close()
        conn.Dispose()
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnEditProfile.Click
        Response.Redirect("EditProfile.aspx")
    End Sub

    Protected Sub addNewCar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles addNewCar.Click
        Response.Redirect("AddCar.aspx")
    End Sub
End Class